package edu.cuit.avatar.generic;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/14 13:34
 */
public class WildCardNeedDemo {
    public static double max(MyStack<? extends Number> stack){
        var max = stack.pop().doubleValue();
        while(!stack.empty()){
            var top = stack.pop().doubleValue();
            if(top > max)
                max = top;
        }
        return max;
    }

    public static void main(String[] args) {
        var stack = new MyStack<Double>();
        stack.push(10.0);
        stack.push(20.2);
        stack.push(50.3);
        System.out.println("max:" + max(stack));

        var stack2 = new MyStack<Integer>();
        for(var i = 0; i < 20; i++)
            stack2.push(i);
        clear(stack2);
    }

    public static void clear(MyStack<?> stack){
        while(!stack.empty())
            System.out.print(stack.pop() + " ");
    }
}
